package enums

type DriverEnum int

const (
	DriverOfMysql DriverEnum = iota + 1
	DriverOfPostgres
	DriverOfSqlserver
	DriverOfSqlite
)

type DriverType struct {
	Name      string
	SourceFmt string
}

func (it DriverEnum) Get() DriverType {
	switch it {
	case DriverOfMysql:
		return DriverType{Name: "mysql", SourceFmt: "#username:#password@tcp(#host:#port)/#dbname?charset=utf8&parseTime=True&loc=Local&timeout=3s"}
	case DriverOfPostgres:
		return DriverType{Name: "postgres", SourceFmt: "host=#host user=#username password=#password dbname=#dbname port=#port sslmode=disable TimeZone=Asia/Shanghai connect_timeout=3"}
	case DriverOfSqlserver:
		return DriverType{Name: "sqlserver", SourceFmt: "sqlserver://#username:#password@#host:#port?database=#dbname&encrypt=disable"}
	case DriverOfSqlite:
		return DriverType{Name: "sqlite3"}
	default:
		return DriverType{}
	}
}

func GetDriverType(driverName string) DriverType {
	switch driverName {
	case DriverOfMysql.Get().Name:
		return DriverOfMysql.Get()
	case DriverOfPostgres.Get().Name:
		return DriverOfPostgres.Get()
	case DriverOfSqlserver.Get().Name:
		return DriverOfSqlserver.Get()
	case DriverOfSqlite.Get().Name:
		return DriverOfSqlite.Get()
	default:
		return DriverType{}
	}
}
